(function (vc, vm) {

    vc.extends({
        data: {
            editShopConfigInfo: {
                scId: '',
                shopId: '',
                ostartTime: '',
                oendTime: '',
                sendWay:'',
                sendFee:'0'
            }
        },
        _initMethod: function () {
            vc.initHourMinute('ostartTime',function(_value){
                $that.editShopConfigInfo.ostartTime = _value;
            });
            vc.initHourMinute('oendTime',function(_value){
                $that.editShopConfigInfo.oendTime = _value;
            });
        },
        _initEvent: function () {
            vc.on('editShopConfig', 'openEditShopConfigModal', function (_params) {
                $that.refreshEditShopConfigInfo();
                $('#editShopConfigModel').modal('show');
                vc.copyObject(_params, $that.editShopConfigInfo);
                $that.editShopConfigInfo.shopId = vc.getCurrentCommunity().shopId;
            });
        },
        methods: {
            editShopConfigValidate: function () {
                return vc.validate.validate({
                    editShopConfigInfo: $that.editShopConfigInfo
                }, {
                    'editShopConfigInfo.shopId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "店铺ID不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "店铺ID不能超过30"
                        },
                    ],
                    'editShopConfigInfo.ostartTime': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "营业开始时间不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "64",
                            errInfo: "营业开始时间不能超过64"
                        },
                    ],
                    'editShopConfigInfo.oendTime': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "营业结束时间不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "64",
                            errInfo: "营业结束时间不能超过64"
                        },
                    ],

                });
            },
            editShopConfig: function () {
                if (!$that.editShopConfigValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                vc.http.apiPost(
                    '/shopConfig.updateShopConfig',
                    JSON.stringify($that.editShopConfigInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editShopConfigModel').modal('hide');
                            vc.emit('shopConfig', 'listShopConfig', {});
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);
                    });
            },
            refreshEditShopConfigInfo: function () {
                $that.editShopConfigInfo = {
                    scId: '',
                    shopId: '',
                    ostartTime: '',
                    oendTime: '',
                    sendWay:'',
                    sendFee:'0'
                }
            }
        }
    });

})(window.vc, window.$that);
